use std::time::Duration;

use rand::prelude::*;

pub fn sleep_millisecs(start: u64, end: u64) -> u64 {
    let mut rng = rand::thread_rng();
    let millis = rng.gen_range(start..end);
    std::thread::sleep(Duration::from_millis(millis));
    millis
}

pub fn sleep_secs(secs: u64) {
    std::thread::sleep(Duration::from_secs(secs));
}

pub fn sleep_minutes(minutes: u64) {
    std::thread::sleep(Duration::from_secs(60 * minutes));
}

pub fn sleep_loop(name: &str, count_loop: u32) {
    let count_loop_new = count_loop.max(10).min(100_0000);
    
    for index in 1..(count_loop_new + 1) {
        info!("{name} 心跳: 1分钟1次, {index} / {count_loop_new}.");
        std::thread::sleep(std::time::Duration::from_secs(60));
    }
    warn!("{name} 心跳完成 {count_loop_new} 次！");
}